export default {
	async myWallet() {
		let res = await this.httptool.post(this.apis.myWallet, null);
		this.tableData = this.tool.trimNull(res.data.list, []);
		this.totalBalance = this.tool.trimNull(res.data.totalBalance, 0);

	},
	async getmerchants(type) {
		let url = this.apis.merchant;
		if(type == 2) { //提现
			url = this.apis.commonMerchant;
		}
		let res = await this.httptool.post(url, null);
		let list = this.tool.trimNull(res.data, []);
		this.companys=list;
//		if(list.length > 0) {
//			list.map((item) => {
//				this.companys.push({
//					id: item.id,
//					name: item.userName
//				});
//			});
//		}

	},
	async getbanks() {
		let params = {
			pageNum: 1,
			pageSize: 30
		};
		let res = await this.httptool.post(this.apis.bankCardList, this.params);
		let list = this.tool.trimNull(res.data, []);
		this.bankList = list;
		this.banks = [];
		if(list.length > 0) {
			list.map((item) => {
				this.banks.push({
					id: item.id,
					name: item.cardTypeCN + "(" + item.cardNumber.substr(item.cardNumber.length - 4) + ")"
				});
			});
		}

	},
	async save() {

		let rule = [{
			name: 'balance',
			label: this.operatetype == 1 ? '充值金额' : '提现金额',
			rule: ['validateN_']
		}, {
			name: 'userId',
			label: '贸易商',
			rule: ['validateEmpty_']
		}, {
			name: 'bankId',
			label: '银行卡',
			rule: ['validateEmpty_']
		}];

		if(!this.validatetool.validate(this, this.modelData, rule)) {
			return;
		}
		let url = this.apis.recharge;
		if(this.operatetype == 2) {
			url = this.apis.withdraw;
		}
		let msg = "充值成功！";
		let res = await this.httptool.post(url, this.modelData);

		if(this.operatetype == 2) {
			msg = "提现成功！";
		}
		this.$message(msg);
		setTimeout(()=>{
				history.back();
			},1500);

	},

	async getExpenserecord() {
		let params = {};
		params.userId =this.$store.state.userInfo.id;
		console.log(this.$store.state.userInfo.id);
		let res = await this.httptool.post(this.apis.walletRecord, {});
		this.tableData = this.tool.trimNull(res.data, []);

	}
}